package display.controller;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import display.structure.Belt;

import prefuse.action.ItemAction;
import prefuse.visual.VisualItem;

public class DumpInfoTimmer extends ItemAction{
	FileWriter fw = null;
	Belt belt = null;
	WheelSpeedAnimator[] wheels = null;
	public DumpInfoTimmer(String fileName, Belt belt, WheelSpeedAnimator ... wheels){
		try {
			fw = new FileWriter(new File(fileName));
		} catch (IOException e) {
			e.printStackTrace();
		}
		this.belt = belt;
		this.wheels = wheels;
	}
	@Override
	public void run(double frac) {
		long currentTime = System.currentTimeMillis();
		try {
			fw.write(currentTime+":"+belt.companyName+":"+belt.getSpeed()+"\n");
			for(WheelSpeedAnimator wheel : wheels){
				fw.write(currentTime+":"+wheel.getWheel().name+":"+wheel.getRadPerSec()+"\n");
			}
			fw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
		super.run(frac);
	}
	@Override
	public void process(VisualItem item, double frac) {
		
	}
}
